package com.weiyi.mashangzhu.Roomer.Activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.okhttp.Request;
import com.weiyi.mashangzhu.API.API;
import com.weiyi.mashangzhu.Base.BaseActivity;
import com.weiyi.mashangzhu.R;
import com.weiyi.mashangzhu.Utils.GlideImgManager;
import com.weiyi.mashangzhu.Utils.LoadingDialog;
import com.weiyi.mashangzhu.Utils.SPUtils;
import com.weiyi.mashangzhu.Utils.T;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import org.json.JSONException;
import org.json.JSONObject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class CommentActivity extends BaseActivity {

    @BindView(R.id.health_good)
    TextView healthGood;
    @BindView(R.id.health_common)
    TextView healthCommon;
    @BindView(R.id.health_bad)
    TextView healthBad;
    @BindView(R.id.service_good)
    TextView serviceGood;
    @BindView(R.id.service_common)
    TextView serviceCommon;
    @BindView(R.id.service_bad)
    TextView serviceBad;
    @BindView(R.id.traffic_good)
    TextView trafficGood;
    @BindView(R.id.traffic_common)
    TextView trafficCommon;
    @BindView(R.id.traffic_bad)
    TextView trafficBad;
    @BindView(R.id.cost_good)
    TextView costGood;
    @BindView(R.id.cost_common)
    TextView costCommon;
    @BindView(R.id.cost_bad)
    TextView costBad;
    String order_id;
    @BindView(R.id.host_good)
    TextView hostGood;
    @BindView(R.id.host_common)
    TextView hostCommon;
    @BindView(R.id.host_bad)
    TextView hostBad;
    int health = 5;
    int service = 5;
    int traffic = 5;
    int cost = 5;
    int host = 5;
    @BindView(R.id.content)
    EditText content;
    String img_url, title, type, price;
    @BindView(R.id.order_detail_img)
    ImageView orderDetailImg;
    @BindView(R.id.order_detail_title)
    TextView orderDetailTitle;
    @BindView(R.id.order_detail_type)
    TextView orderDetailType;
    @BindView(R.id.order_detail_price)
    TextView orderDetailPrice;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_comment);
        ButterKnife.bind(this);
        Intent intent = getIntent();
        order_id = intent.getStringExtra("order_id");
        img_url = intent.getStringExtra("img_url");
        title = intent.getStringExtra("title");
        type = intent.getStringExtra("type");
        price = intent.getStringExtra("price");
        GlideImgManager.glideLoader(this, API.BaseApi_url + img_url, R.mipmap.errer, orderDetailImg);
        orderDetailTitle.setText(title);
        orderDetailPrice.setText("¥"+price+"/晚");
        orderDetailType.setText(type+"居室");

//        T.showShort(this, "order_id=" + order_id);
    }

    @OnClick({R.id.back, R.id.fabiao, R.id.health_good, R.id.health_common, R.id.health_bad, R.id.service_good, R.id.service_common, R.id.service_bad, R.id.traffic_good, R.id.traffic_common, R.id.traffic_bad, R.id.cost_good, R.id.cost_common, R.id.cost_bad, R.id.host_bad, R.id.host_common, R.id.host_good})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.fabiao:
                LoadingDialog.show(CommentActivity.this);
                OkHttpUtils.get().addParams("token", SPUtils.get(this, "token", "") + "")
                        .addParams("id", order_id + "")
                        .addParams("eHealth", health + "")
                        .addParams("eService", service + "")
                        .addParams("eTraffic", traffic + "")
                        .addParams("eCounts", cost + "")
                        .addParams("eHostevaluate", host + "")
                        .addParams("eContent", content.getText() + "")
                        .addParams("eCheck", "1")
                        .url(API.BaseApi_R + API.Comment_Api)
                        .build()
                        .execute(new StringCallback() {
                            @Override
                            public void onError(Request request, Exception e) {
                                LoadingDialog.dismiss(CommentActivity.this);
                                T.showShort(CommentActivity.this, "数据获取失败，请稍后再试");
                            }

                            @Override
                            public void onResponse(String response) {
                                LoadingDialog.dismiss(CommentActivity.this);
                                try {
                                    JSONObject jsonObject = new JSONObject(response);
                                    int status = jsonObject.getInt("status");
                                    if (status == 0) {
                                        T.showShort(CommentActivity.this, "评价成功");
                                        finish();
                                    } else {
                                        T.showShort(CommentActivity.this, "评价失败");
                                    }
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }

                            }
                        });
                break;
            case R.id.health_good:
                health = 5;
                healthGood.setTextColor(this.getResources().getColor(R.color.white));
                healthGood.setBackground(this.getResources().getDrawable(R.drawable.shape_comment_blue_bg));
                healthCommon.setTextColor(this.getResources().getColor(R.color.colorPrimary));
                healthCommon.setBackground(this.getResources().getDrawable(R.drawable.shape_comment_white_bg));
                healthBad.setTextColor(this.getResources().getColor(R.color.colorPrimary));
                healthBad.setBackground(this.getResources().getDrawable(R.drawable.shape_comment_white_bg));

                break;
            case R.id.health_common:
                health = 4;
                healthCommon.setTextColor(this.getResources().getColor(R.color.white));
                healthCommon.setBackground(this.getResources().getDrawable(R.drawable.shape_comment_blue_bg));
                healthGood.setTextColor(this.getResources().getColor(R.color.colorPrimary));
                healthGood.setBackground(this.getResources().getDrawable(R.drawable.shape_comment_white_bg));
                healthBad.setTextColor(this.getResources().getColor(R.color.colorPrimary));
                healthBad.setBackground(this.getResources().getDrawable(R.drawable.shape_comment_white_bg));
                break;
            case R.id.health_bad:
                health = 3;
                healthBad.setTextColor(this.getResources().getColor(R.color.white));
                healthBad.setBackground(this.getResources().getDrawable(R.drawable.shape_comment_blue_bg));
                healthGood.setTextColor(this.getResources().getColor(R.color.colorPrimary));
                healthGood.setBackground(this.getResources().getDrawable(R.drawable.shape_comment_white_bg));
                healthCommon.setTextColor(this.getResources().getColor(R.color.colorPrimary));
                healthCommon.setBackground(this.getResources().getDrawable(R.drawable.shape_comment_white_bg));
                break;
            case R.id.service_good:
                service = 5;
                serviceGood.setTextColor(this.getResources().getColor(R.color.white));
                serviceGood.setBackground(this.getResources().getDrawable(R.drawable.shape_comment_blue_bg));
                serviceCommon.setTextColor(this.getResources().getColor(R.color.colorPrimary));
                serviceCommon.setBackground(this.getResources().getDrawable(R.drawable.shape_comment_white_bg));
                serviceBad.setTextColor(this.getResources().getColor(R.color.colorPrimary));
                serviceBad.setBackground(this.getResources().getDrawable(R.drawable.shape_comment_white_bg));

                break;
            case R.id.service_common:
                service = 4;
                serviceCommon.setTextColor(this.getResources().getColor(R.color.white));
                serviceCommon.setBackground(this.getResources().getDrawable(R.drawable.shape_comment_blue_bg));
                serviceGood.setTextColor(this.getResources().getColor(R.color.colorPrimary));
                serviceGood.setBackground(this.getResources().getDrawable(R.drawable.shape_comment_white_bg));
                serviceBad.setTextColor(this.getResources().getColor(R.color.colorPrimary));
                serviceBad.setBackground(this.getResources().getDrawable(R.drawable.shape_comment_white_bg));
                break;
            case R.id.service_bad:
                service = 3;
                serviceBad.setTextColor(this.getResources().getColor(R.color.white));
                serviceBad.setBackground(this.getResources().getDrawable(R.drawable.shape_comment_blue_bg));
                serviceGood.setTextColor(this.getResources().getColor(R.color.colorPrimary));
                serviceGood.setBackground(this.getResources().getDrawable(R.drawable.shape_comment_white_bg));
                serviceCommon.setTextColor(this.getResources().getColor(R.color.colorPrimary));
                serviceCommon.setBackground(this.getResources().getDrawable(R.drawable.shape_comment_white_bg));
                break;
            case R.id.traffic_good:
                traffic = 5;
                trafficGood.setTextColor(this.getResources().getColor(R.color.white));
                trafficGood.setBackground(this.getResources().getDrawable(R.drawable.shape_comment_blue_bg));
                trafficCommon.setTextColor(this.getResources().getColor(R.color.colorPrimary));
                trafficCommon.setBackground(this.getResources().getDrawable(R.drawable.shape_comment_white_bg));
                trafficBad.setTextColor(this.getResources().getColor(R.color.colorPrimary));
                trafficBad.setBackground(this.getResources().getDrawable(R.drawable.shape_comment_white_bg));
                break;
            case R.id.traffic_common:
                traffic = 4;
                trafficCommon.setTextColor(this.getResources().getColor(R.color.white));
                trafficCommon.setBackground(this.getResources().getDrawable(R.drawable.shape_comment_blue_bg));
                trafficGood.setTextColor(this.getResources().getColor(R.color.colorPrimary));
                trafficGood.setBackground(this.getResources().getDrawable(R.drawable.shape_comment_white_bg));
                trafficBad.setTextColor(this.getResources().getColor(R.color.colorPrimary));
                trafficBad.setBackground(this.getResources().getDrawable(R.drawable.shape_comment_white_bg));
                break;
            case R.id.traffic_bad:
                traffic = 3;
                trafficBad.setTextColor(this.getResources().getColor(R.color.white));
                trafficBad.setBackground(this.getResources().getDrawable(R.drawable.shape_comment_blue_bg));
                trafficCommon.setTextColor(this.getResources().getColor(R.color.colorPrimary));
                trafficCommon.setBackground(this.getResources().getDrawable(R.drawable.shape_comment_white_bg));
                trafficGood.setTextColor(this.getResources().getColor(R.color.colorPrimary));
                trafficGood.setBackground(this.getResources().getDrawable(R.drawable.shape_comment_white_bg));
                break;
            case R.id.cost_good:
                cost = 5;
                costGood.setTextColor(this.getResources().getColor(R.color.white));
                costGood.setBackground(this.getResources().getDrawable(R.drawable.shape_comment_blue_bg));
                costCommon.setTextColor(this.getResources().getColor(R.color.colorPrimary));
                costCommon.setBackground(this.getResources().getDrawable(R.drawable.shape_comment_white_bg));
                costBad.setTextColor(this.getResources().getColor(R.color.colorPrimary));
                costBad.setBackground(this.getResources().getDrawable(R.drawable.shape_comment_white_bg));
                break;
            case R.id.cost_common:
                cost = 4;
                costCommon.setTextColor(this.getResources().getColor(R.color.white));
                costCommon.setBackground(this.getResources().getDrawable(R.drawable.shape_comment_blue_bg));
                costGood.setTextColor(this.getResources().getColor(R.color.colorPrimary));
                costGood.setBackground(this.getResources().getDrawable(R.drawable.shape_comment_white_bg));
                costBad.setTextColor(this.getResources().getColor(R.color.colorPrimary));
                costBad.setBackground(this.getResources().getDrawable(R.drawable.shape_comment_white_bg));
                break;
            case R.id.cost_bad:
                cost = 3;
                costBad.setTextColor(this.getResources().getColor(R.color.white));
                costBad.setBackground(this.getResources().getDrawable(R.drawable.shape_comment_blue_bg));
                costCommon.setTextColor(this.getResources().getColor(R.color.colorPrimary));
                costCommon.setBackground(this.getResources().getDrawable(R.drawable.shape_comment_white_bg));
                costGood.setTextColor(this.getResources().getColor(R.color.colorPrimary));
                costGood.setBackground(this.getResources().getDrawable(R.drawable.shape_comment_white_bg));
                break;
            case R.id.host_good:
                host = 5;
                hostGood.setTextColor(this.getResources().getColor(R.color.white));
                hostGood.setBackground(this.getResources().getDrawable(R.drawable.shape_comment_blue_bg));
                hostCommon.setTextColor(this.getResources().getColor(R.color.colorPrimary));
                hostCommon.setBackground(this.getResources().getDrawable(R.drawable.shape_comment_white_bg));
                hostBad.setTextColor(this.getResources().getColor(R.color.colorPrimary));
                hostBad.setBackground(this.getResources().getDrawable(R.drawable.shape_comment_white_bg));
                break;
            case R.id.host_common:
                host = 4;
                hostCommon.setTextColor(this.getResources().getColor(R.color.white));
                hostCommon.setBackground(this.getResources().getDrawable(R.drawable.shape_comment_blue_bg));
                hostGood.setTextColor(this.getResources().getColor(R.color.colorPrimary));
                hostGood.setBackground(this.getResources().getDrawable(R.drawable.shape_comment_white_bg));
                hostBad.setTextColor(this.getResources().getColor(R.color.colorPrimary));
                hostBad.setBackground(this.getResources().getDrawable(R.drawable.shape_comment_white_bg));
                break;
            case R.id.host_bad:
                host = 3;
                hostBad.setTextColor(this.getResources().getColor(R.color.white));
                hostBad.setBackground(this.getResources().getDrawable(R.drawable.shape_comment_blue_bg));
                hostCommon.setTextColor(this.getResources().getColor(R.color.colorPrimary));
                hostCommon.setBackground(this.getResources().getDrawable(R.drawable.shape_comment_white_bg));
                hostGood.setTextColor(this.getResources().getColor(R.color.colorPrimary));
                hostGood.setBackground(this.getResources().getDrawable(R.drawable.shape_comment_white_bg));
                break;
        }
    }
}
